package com.compass.doctor.ui.mine.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.compass.doctor.R
import com.compass.doctor.databinding.LayoutUsefulCateExpressionsBinding

import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.constant.UsefulTypeOpeEnum
import com.compass.framework.ext.invisible
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.model.Drug
import com.compass.framework.model.UsefulExpressionsCate
import com.compass.framework.utils.getDrawableResource
import com.netease.yunxin.kit.chatkit.ui.databinding.LayoutUsefulExpressionsBinding
import com.netease.yunxin.kit.chatkit.ui.model.UsefulExpressions

/**
 * Description： 常用语分类adapter
 * Date:2024/6/21 15:49
 */
class UsefulExpressionsCateAdapter :
    BaseRecyclerViewAdapter<UsefulExpressionsCate, LayoutUsefulCateExpressionsBinding>() {


    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutUsefulCateExpressionsBinding>,
        item: UsefulExpressionsCate?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvName.text = item.typeName
            tvNumber.text = "${item.count}条"
            if(mType == UsefulTypeOpeEnum.LIST){
               ivStatus.visible()
                ivStatus.setImageResource(R.mipmap.icon_arrow_right)
            }else{
                ivStatus.visible()
                if(item.isSelect){
                    ivStatus.setImageResource(R.mipmap.ic_agreement_select)
                }else{
                    ivStatus.setImageResource(R.mipmap.ic_agreement_default)
                }
            }

        }
    }

    private var mType : UsefulTypeOpeEnum = UsefulTypeOpeEnum.LIST

    fun setmType(type : UsefulTypeOpeEnum) {
        this.mType = type
        notifyDataSetChanged()
    }

    fun getmType(): UsefulTypeOpeEnum {
        return this.mType
    }

    fun getChooseCateIds(): String {
        val listIds = ArrayList<String?>()
        val list = getData()
        list.let {
            for (item in list) {
                if(item.isSelect) listIds.add(item.id)
            }
        }
        return listIds.joinToString(separator = ",")
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutUsefulCateExpressionsBinding {
        return LayoutUsefulCateExpressionsBinding.inflate(layoutInflater, parent, false)
    }
}